package com.ruoyi.course.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.course.domain.CourseCla;
import com.ruoyi.course.service.ICourseClaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 班级管理Controller
 * 
 * @author UtadaCCC
 * @date 2025-06-18
 */
@RestController
@RequestMapping("/course/courseCla")
public class CourseClaController extends BaseController
{
    @Autowired
    private ICourseClaService courseClaService;

    /**
     * 查询班级管理列表
     */
//    @PreAuthorize("@ss.hasPermi('course:courseCla:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseCla courseCla)
    {
        startPage();
        List<CourseCla> list = courseClaService.selectCourseClaList(courseCla);
        return getDataTable(list);
    }

    /**
     * 导出班级管理列表
     */
//    @PreAuthorize("@ss.hasPermi('course:courseCla:export')")
    @Log(title = "班级管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseCla courseCla)
    {
        List<CourseCla> list = courseClaService.selectCourseClaList(courseCla);
        ExcelUtil<CourseCla> util = new ExcelUtil<CourseCla>(CourseCla.class);
        util.exportExcel(response, list, "班级管理数据");
    }

    /**
     * 获取班级管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('course:courseCla:query')")
    @GetMapping(value = "/{claId}")
    public AjaxResult getInfo(@PathVariable("claId") Integer claId)
    {
        return success(courseClaService.selectCourseClaByClaId(claId));
    }

    /**
     * 新增班级管理
     */
//    @PreAuthorize("@ss.hasPermi('course:courseCla:add')")
    @Log(title = "班级管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseCla courseCla)
    {
        return toAjax(courseClaService.insertCourseCla(courseCla));
    }

    /**
     * 修改班级管理
     */
//    @PreAuthorize("@ss.hasPermi('course:courseCla:edit')")
    @Log(title = "班级管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseCla courseCla)
    {
        return toAjax(courseClaService.updateCourseCla(courseCla));
    }

    /**
     * 删除班级管理
     */
//    @PreAuthorize("@ss.hasPermi('course:courseCla:remove')")
    @Log(title = "班级管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{claIds}")
    public AjaxResult remove(@PathVariable Integer[] claIds)
    {
        return toAjax(courseClaService.deleteCourseClaByClaIds(claIds));
    }

    /**
     * 查询班级管理列表
     */
//    @PreAuthorize("@ss.hasPermi('course:courseCla:List')")
    @GetMapping("/selectCourseClassList")
    public TableDataInfo selectCourseClassList(CourseCla courseCla)
    {
        System.out.println(courseCla+"---------------sbnsz------------------------");
        startPage();
        List<CourseCla> list = courseClaService.selectCourseClassList(courseCla);
        System.out.println(list+"-----------list-----------");
        return getDataTable(list);
    }

    /**
     * 查询课程管理列表
     */
//    @PreAuthorize("@ss.hasPermi('course:courseCla:List')")
    @GetMapping("/selectCourseList")
    public TableDataInfo selectCourseList(CourseCla courseCla)
    {
        System.out.println(courseCla+"--------66666-------");
        startPage();
        List<CourseCla> list = courseClaService.selectCourseList(courseCla);
        System.out.println(list+"-----------list-----------");
        return getDataTable(list);
    }

    @DeleteMapping("/deleteStuId/{claId}")
    public AjaxResult deleteStuId(@PathVariable Integer claId)
    {
        System.out.println(claId +"==================12=======2=3==========1====================1==============");
        return success(courseClaService.deleteStuIds(claId));
    }

    @PostMapping("/addBatchCourseStu")
    public AjaxResult addBatchCourseStu(@RequestBody List<CourseCla> courseCla)
    {
        return toAjax(courseClaService.addBatchCourseStu(courseCla));
    }
}
